#include "BlockData.h"

BlockData::BlockData(void)
{

}

BlockData::~BlockData(void)
{
    objectsMoving.clear();
    objectsHit.clear();
    objectsMoveValue.clear();
    objectsMoveTimer.clear();
    objectsMoveStart.clear();
}

void
BlockData::AddObject(int id)
{
    objectsId.push_back(id);
    objectsMoving.push_back(false);
    objectsHit.push_back(false);
    objectsMoveValue.push_back(0);
    objectsMoveTimer.push_back(16); // 60 FPS (16ms)
    objectsMoveStart.push_back(0);
}

void
BlockData::RemoveObject(int id)
{
    int index = GetIndex(id);
    objectsId.erase(objectsId.begin()+index);
    objectsMoving.erase(objectsMoving.begin()+index);
    objectsHit.erase(objectsHit.begin()+index);
    objectsMoveValue.erase(objectsMoveValue.begin()+index);
    objectsMoveTimer.erase(objectsMoveTimer.begin()+index);
    objectsMoveStart.erase(objectsMoveStart.begin()+index);
}

void
BlockData::SetMoving(int id, bool value)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        objectsMoving[index] = value;
    }
}

bool
BlockData::IsMoving(int id)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        return objectsMoving[index];
    }
    return false;
}

void
BlockData::SetHit(int id, bool value)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        objectsHit[index] = value;
    }
}

bool
BlockData::IsHit(int id)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        return objectsHit[index];
    }
    return false;
}

void
BlockData::SetMoveValue(int id, int value)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        objectsMoveValue[index] = value;
    }
}

int
BlockData::GetMoveValue(int id)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        return objectsMoveValue[index];
    }
    return 0;
}

void
BlockData::SetMoveTimer(int id, unsigned int value)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        objectsMoveTimer[index] = value;
    }
}

unsigned int
BlockData::GetMoveTimer(int id)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        return objectsMoveTimer[index];
    }
    return 0;
}

void
BlockData::SetMoveStart(int id, unsigned int value)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        objectsMoveStart[index] = value;
    }
}

unsigned int
BlockData::GetMoveStart(int id)
{
    int index = GetIndex(id);
    if (index != -1)
    {
        return objectsMoveStart[index];
    }
    return 0;
}
